package id.net.iconpln.bb.client.view;

import id.net.iconpln.bb.client.model.Stock;
import id.net.iconpln.bb.client.service.PortRPCService;
import id.net.iconpln.bb.client.service.PortRPCServiceAsync;
import id.net.iconpln.bb.client.service.TransportRPCService;
import id.net.iconpln.bb.client.service.TransportRPCServiceAsync;
import id.net.iconpln.bb.client.util.ClientModule;


import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.DateTimePropertyEditor;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.MultiField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PageBbPortSampling extends LayoutContainer {
	private final PortRPCServiceAsync service = GWT.create(PortRPCService.class);
	private final TransportRPCServiceAsync serviceSampling = GWT.create(TransportRPCService.class);
	private FormBinding formBindings;  
	private FormData formData; 
	private ListStore storeKplAntri, storeSurveyor,storeKplSandar;
	private Grid gridKplBongkar, gridKplAntri,gridKplSandar;
	private ComboBox cboSurveyor;
	private DateField tglTa, time_bongkarD,time_sandarD;
	private TextField<String> noAntri,ash_kirim,cv_kirim,ts_kirim,hgi_kirim,tm_kirim,ash_terima,cv_terima,ts_terima,tm_terima,hgi_terima,vol_kirim,vol_terima;
	private TimeField time_bongkarT,time_sandarT;
	private Button bSubmit;
	private GroupingStore storeKplBongkar;
	
	
	  @Override  
	  protected void onRender(Element parent, int index) {  
	    super.onRender(parent, index);  
	    setLayout(new FitLayout());
	    initStore();
	    
	    formData = new FormData("-20"); 
	    ContentPanel cp = new ContentPanel();  
	   
	    cp.setHeaderVisible(false);
	    cp.setFrame(true);  
	    cp.setSize(900, 400);  
	    cp.setLayout(new RowLayout(Orientation.HORIZONTAL)); 
	  
	    gridKplSandar = createGridSandar();  
	    gridKplSandar.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
	    gridKplSandar.getSelectionModel().addListener(Events.SelectionChange,  
	        new Listener<SelectionChangedEvent<BaseModel>>() {  
	          public void handleEvent(SelectionChangedEvent<BaseModel> be) {  
	            if (be.getSelection().size() > 0) {  	              
//	            	bSubmit.setEnabled(true);
	              formBindings.bind((ModelData) be.getSelection().get(0));  
	            } else {  
	              formBindings.unbind();  
	            }  
	          }  
	        });
	    
	    
	    gridKplBongkar = createGridBongkar();
	    gridKplBongkar.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
	    gridKplBongkar.getSelectionModel().addListener(Events.SelectionChange,  
	        new Listener<SelectionChangedEvent<Stock>>() {  
	          public void handleEvent(SelectionChangedEvent<Stock> be) {  
	            if (be.getSelection().size() > 0) {  
//	            	bSubmit.setEnabled(false);
	              formBindings.bind((ModelData) be.getSelection().get(0));  
	            } else {  
	              formBindings.unbind();  
	            }  
	          }  
	        });
	    ToolBar tbPltu = new ToolBar();
	    tbPltu.add(new LabelToolItem("<b>Data Sampling Kualitas</b>"));
	    tbPltu.add(new SeparatorToolItem());
	    	    
//	    gridship = createGridPreshipment();
	    ToolBar tbSandar = new ToolBar();
	    tbSandar.add(new LabelToolItem("<b>Data Kapal Sandar</b>"));
	    tbSandar.add(new SeparatorToolItem());
	    
	    FormPanel panel = createForm(); 
	    panel.setScrollMode(Scroll.AUTO);
	    formBindings = new FormBinding(panel, true);  
//	    formBindings.setStore((Store) gridKplBongkar.getStore());  
	    
	    
	    ContentPanel pkirim = new ContentPanel();
	    pkirim.setHeaderVisible(false);
	    pkirim.setLayout(new FitLayout());
	    pkirim.add(gridKplBongkar);
	    pkirim.setTopComponent(tbPltu);
	    
	    aktivitasDermaga("sampling","BANDINGSAMPLING","", "");
	    aktivitasDermaga("master","SURVEYOR","", "");
	    
	    ContentPanel pKplSandar = new ContentPanel();
	    pKplSandar.setHeaderVisible(false);
	    pKplSandar.setLayout(new RowLayout(Orientation.HORIZONTAL));
	    pKplSandar.add(gridKplSandar,new RowData(1, 1));
	    pKplSandar.setTopComponent(tbSandar);

	    ContentPanel pKplBongkar = new ContentPanel();
	    pKplBongkar.setHeaderVisible(false);
	    pKplBongkar.setLayout(new RowLayout(Orientation.HORIZONTAL));
	    pKplBongkar.add(gridKplBongkar,new RowData(1, 1));
	    pKplBongkar.setTopComponent(tbPltu);

	    
	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);
	    p.setLayout(new RowLayout(Orientation.VERTICAL));	    	    
//	    p.add(pKplSandar, new RowData(.99, .5));
	    p.add(pKplBongkar, new RowData(.99, 1));
	    
	    cp.add(panel, new RowData(.4, 1));
	    cp.add(p, new RowData(.6, 1));
	    
	    
//		setScrollMode(Scroll.AUTO);		
	    add(cp, new FitData(5));  
	  }  
	  private void initStore(){
		  storeKplBongkar = new GroupingStore(); 
		  storeSurveyor = new ListStore();
	  }

	  private Grid createGridBongkar() {  
		  
		  storeKplBongkar.groupBy("pemasok");  
		  
		    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig();	    	     

		    column = new ColumnConfig();  
		    column.setId("no_pengajuan"); 
		    column.setHidden(true);
		    column.setHeader("No Pengajuan");  
		    column.setWidth(150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("pemasok");  
		    column.setHeader("Pemasok");  
		    column.setWidth(150);  
		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("status");  
		    column.setHeader("Status");  
		    column.setWidth(150);  
		    configs.add(column); 

		    
		    column = new ColumnConfig();  
		    column.setId("nama_transport");
		    column.setHidden(true);
		    column.setHeader("Nama kapal");    
		    column.setWidth(150);    
		    configs.add(column);  

		    column = new ColumnConfig();  
		    column.setId("no_pengiriman");
		    column.setHidden(true);
		    column.setHeader("No Pengiriman");  
		    column.setWidth(100);  
		    configs.add(column);  	
		    		    
		    column = new ColumnConfig();  
		    column.setId("nama_surveyor"); 
//		    column.setHidden(true);
		    column.setHeader("Nama Surveyor");  
		    column.setWidth(100);  
		    configs.add(column);  	  

		    column = new ColumnConfig();  
		    column.setId("tanggal");  
		    column.setHeader("Tanggal");  
		    column.setDateTimeFormat(DateTimeFormat.getFormat("dd/MM/yyyy hh.mm"));
		    column.setWidth(150);  
		    configs.add(column);  

		    
		    column = new ColumnConfig();  
		    column.setId("ash");  
		    column.setHeader("Ash");  
		    column.setWidth(100);  
		    configs.add(column);

//		    column = new ColumnConfig();  
//		    column.setId("ash_terima");  
//		    column.setHeader("Ash Terima");  
//		    column.setWidth(100);  
//		    configs.add(column);
		    
		    column = new ColumnConfig();  
		    column.setId("cv");  
		    column.setHeader("CV");  
		    column.setWidth(100);  
		    configs.add(column);  	  

//		    column = new ColumnConfig();  
//		    column.setId("cv_terima");  
//		    column.setHeader("CV Terim");  
//		    column.setWidth(100);  
//		    configs.add(column);  
		    
		    column = new ColumnConfig();  
		    column.setId("tm");  
		    column.setHeader("TM");  
		    column.setWidth(100);  
		    configs.add(column);  	  

//		    column = new ColumnConfig();  
//		    column.setId("tm_terima");  
//		    column.setHeader("TM Terima");  
//		    column.setWidth(100);  
//		    configs.add(column);  

		    column = new ColumnConfig();  
		    column.setId("ts");  
		    column.setHeader("TS");  
		    column.setWidth(100);  
		    configs.add(column);  	  

//		    column = new ColumnConfig();  
//		    column.setId("ts_terima");  
//		    column.setHeader("TS Terima");  
//		    column.setWidth(100);  
//		    configs.add(column);  

		    column = new ColumnConfig();  
		    column.setId("hgi");  
		    column.setHeader("HGI");  
		    column.setWidth(100);  
		    configs.add(column);  	  

		    
		    column = new ColumnConfig();  
		    column.setId("volume");  
		    column.setHeader("Volume");  
		    column.setWidth(100);  
		    configs.add(column);  	  
		    
		    column = new ColumnConfig();  
		    column.setId("hgi_terima");  
		    column.setHidden(true);
		    column.setHeader("HGI Terima");  
		    column.setWidth(100);  
		    configs.add(column);  
		    column = new ColumnConfig();  
		    
		    column.setId("hgi_kirim");  
		    column.setHidden(true);
		    column.setHeader("HGI");  
		    column.setWidth(100);  
		    configs.add(column);  

		    
		    storeKplBongkar.setMonitorChanges(true);  
		 
		    final ColumnModel cm = new ColumnModel(configs);  
	  
		    GroupingView view = new GroupingView();  
		    view.setShowGroupedColumn(false);  
//		    view.setForceFit(true);  
		    view.setGroupRenderer(new GridGroupRenderer() {  
			@Override
			public String render(GroupColumnData data) {
				// TODO Auto-generated method stub
				  String f = cm.getColumnById(data.field).getHeader();  
			        String l = data.models.size() == 1 ? "Item" : "Items";  
			        return f + ": " + data.group ; //+ " (" + data.models.size() + " " + l + ")";
			}  
		    });  

		    
	    gridKplBongkar = new Grid(storeKplBongkar, cm);  
	    gridKplBongkar.getView().setEmptyText("Data Empty");
	    gridKplBongkar.setView(view);  
	    gridKplBongkar.setLoadMask(true);  
	    gridKplBongkar.mask("load Data ...","x-mask-loading");
	    gridKplBongkar.setBorders(false);  
//	    grid.setAutoExpandColumn("pemasok");  
	    gridKplBongkar.setBorders(true);  
	    gridKplBongkar.addListener(Events.CellClick, new Listener<BaseEvent>() {            
        public void handleEvent(BaseEvent ge) {
        	try{

//        	   MessageBox.alert("info", " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("ash").toString() + " " +
//						 " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("cv").toString()+ " " + 
//						 " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("ts").toString()+" " + 
//						 " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("tm").toString()+" " +
//						 " " +gridKplBongkar.getSelectionModel().getSelectedItem().get("hgi").toString()
//        			   , null);

        	   ash_kirim.setValue(gridKplBongkar.getSelectionModel().getSelectedItem().get("ash").toString());
        	cv_kirim.setValue(gridKplBongkar.getSelectionModel().getSelectedItem().get("cv").toString());
        	ts_kirim.setValue(gridKplBongkar.getSelectionModel().getSelectedItem().get("ts").toString());
        	tm_kirim.setValue(gridKplBongkar.getSelectionModel().getSelectedItem().get("tm").toString());
        	hgi_kirim.setValue(gridKplBongkar.getSelectionModel().getSelectedItem().get("hgi").toString());
        	vol_kirim.setValue(gridKplBongkar.getSelectionModel().getSelectedItem().get("vol_kirim").toString());
//        		String mulai_sandar = gridKplBongkar.getSelectionModel().getSelectedItem().get("time_merapat");
//            	time_sandarT.setRawValue("00.00");
//            	time_sandarD.setRawValue(mulai_sandar);
            	

//            	Info.display("Debug " ,gridKplBongkar.getSelectionModel().getSelectedItem().get("ash").toString() + " " +
//            						 " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("cv").toString()+ " " + 
//            						 " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("ts").toString()+" " + 
//            						 " " + gridKplBongkar.getSelectionModel().getSelectedItem().get("tm").toString()+" " +
//            						 " " +gridKplBongkar.getSelectionModel().getSelectedItem().get("hgi").toString());

            	
        	}catch (Exception e) {
					// TODO: handle exception
        		e.getMessage();
				}

         	
        }
		});

	    return gridKplBongkar;  
	  }   
	 
 
	  
	  private FormPanel createForm() {  
	    FormPanel panel = new FormPanel();	    
	    panel.setHeaderVisible(false);
	    
	    FieldSet fieldSet = new FieldSet();  
	    fieldSet.setHeading("Pengambilan Sampling");  
	    fieldSet.setCollapsible(false);
	    
	  
	    FormLayout layout = new FormLayout();  
	    layout.setLabelWidth(130);  
	    fieldSet.setLayout(layout);  

	    final TextField<String> no_bongkar = new TextField<String>();  
	    no_bongkar.setName("no_pengiriman");  
	    no_bongkar.setFieldLabel("No Pengiriman");    
	    fieldSet.add(no_bongkar, formData);	  	  
	    
	    final TextField<String> no_pengiriman = new TextField<String>();  
	    no_pengiriman.setName("no_pengiriman");  
	    no_pengiriman.setVisible(false);
	    no_pengiriman.setFieldLabel("No Pengiriman");    
	    fieldSet.add(no_pengiriman, formData);	  	  
	    	     
	    TextField<String> pemasok = new TextField<String>();
	    pemasok.setName("pemasok");  
	    pemasok.setFieldLabel("Pemasok");	    
	    fieldSet.add(pemasok, formData);	
	    
	    TextField<String> nama_transport = new TextField<String>();
	    nama_transport.setName("nama_transport");  
	    nama_transport.setFieldLabel("Kpl / Tongkang");	    
	    fieldSet.add(nama_transport, formData);
	    
//	    TextField<String> kode_jetty = new TextField<String>();
//	    kode_jetty.setName("kode_jetty");  
//	    kode_jetty.setFieldLabel("Jetty");	    
//	    fieldSet.add(kode_jetty, formData);
	    
	    
	    
	    panel.add(fieldSet);  	     

	    FieldSet fieldSet3 = new FieldSet();  
	    fieldSet3.setHeading("Kualitas & Kuantitas Penerimaan");  
	    fieldSet3.setCollapsible(false);

	    FormLayout layout4 = new FormLayout();  
	    layout4.setLabelWidth(70);  
	    fieldSet3.setLayout(layout4);  

	    
	    MultiField multi_terima = new MultiField();
	    multi_terima.setFieldLabel("Ash");
	    multi_terima.setSpacing(20);
	    
	    ash_terima = new TextField<String>();
	    ash_terima.setName("ash_terima");  
	    ash_terima.setWidth(90);
//	    ash_kirim.setFieldLabel("Ash");    
//	    fieldSet2.add(ash_kirim, formData);
	    multi_terima.add(ash_terima);   	    
	    
	    LabelField lcvterima = new LabelField("CV:");
	    lcvterima.setWidth(20);
	    multi_terima.add(lcvterima);
	    
	    cv_terima = new TextField<String>();	    
	    cv_terima.setName("cv_terima");  
	    cv_terima.setWidth(90);
//	    cv_kirim.setFieldLabel("CV");    
//	    fieldSet2.add(cv_kirim, formData);

	    multi_terima.add(cv_terima);
	    
	    fieldSet3.add(multi_terima, formData);
	    
	    MultiField multi_terima_tm_ts = new MultiField();
	    multi_terima_tm_ts.setFieldLabel("TM");
	    multi_terima_tm_ts.setSpacing(20);
	    
	    tm_terima = new TextField<String>();
//	    DateField berangkat = new DateField();
	    tm_terima.setName("tm_terima");  
	    tm_terima.setFieldLabel("TM");    
	    tm_terima.setWidth(90);
//	    fieldSet2.add(tm_kirim, formData);	
	    
	    multi_terima_tm_ts.add(tm_terima);
	    
	    LabelField ltsterima = new LabelField("TS:");
	    ltsterima.setWidth(20);
	    multi_terima_tm_ts.add(ltsterima);
	    
	    
	    ts_terima = new TextField<String>();
//	    DateFielterimakirim.setName("ts");  
	    ts_terima.setWidth(90);
	    ts_terima.setName("ts_terima");
//	    ts_kirim.setFieldLabel("TS");    
//	    fieldSet2.add(ts_kirim, formData);
	    
	    multi_terima_tm_ts.add(ts_terima);	   	    
	    fieldSet3.add(multi_terima_tm_ts, formData);
	    
	    MultiField multi_terima_hgi_vol = new MultiField();
	    multi_terima_hgi_vol.setFieldLabel("HGI");
	    multi_terima_hgi_vol.setSpacing(20);
	    
	    
	    
	    hgi_terima = new TextField<String>();
	    hgi_terima.setName("hgi_terima");  
	    hgi_terima.setWidth(90);
	    hgi_terima.setFieldLabel("HGI");    
//	    fieldSet3.add(hgi_terima, formData);	  
	    
	    multi_terima_hgi_vol.add(hgi_terima);
	    
	    LabelField vollab = new LabelField("Vol:");
	    vollab.setWidth(20);
	    multi_terima_hgi_vol.add(vollab);
	    
	    	    	   
	    vol_terima = new TextField<String>();
	    vol_terima.setName("vol_terima");  
	    vol_terima.setFieldLabel("Vol:");	    
	    vol_terima.setWidth(90);
//	    fieldSet3.add(vol_terima, formData);
	    
	    multi_terima_hgi_vol.add(vol_terima);
	   
	    fieldSet3.add(multi_terima_hgi_vol, formData);
	    

	    MultiField multi_terima_tgl_sur = new MultiField();
	    multi_terima_tgl_sur.setFieldLabel("Surveyor");
	    multi_terima_tgl_sur.setSpacing(20);	    	    
//	    
	    
	    cboSurveyor = new ComboBox();  
	    cboSurveyor.setName("id_surveyor");  
	    cboSurveyor.setFieldLabel("Surveyor");
	    cboSurveyor.setEmptyText("Select Surveyor...");  
	    cboSurveyor.setDisplayField("nama_surveyor");
//	    cboSurveyor.setWidth(100);
	    cboSurveyor.setStore(storeSurveyor);  
	    cboSurveyor.setTypeAhead(true);  
	    cboSurveyor.setTriggerAction(TriggerAction.ALL);
	    cboSurveyor.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
	    	@Override
	    	public void selectionChanged(SelectionChangedEvent<ModelData> se) {
	    		// TODO Auto-generated method stub
	    		aktivitasDermaga("master","SURVEYOR","", "");    		
	    	}
		});
	    
//	    
	    multi_terima_tgl_sur.add(cboSurveyor);
	    fieldSet3.add(multi_terima_tgl_sur, formData);
//	    LabelField ltglsur = new LabelField("TGL:");
//	    ltglsur.setWidth(20);
	    
//	    multi_terima_tgl_sur.add(ltglsur);
	    
	    MultiField multi_terima_tgl_p = new MultiField();
	    multi_terima_tgl_p.setFieldLabel("Tanggal");
	    multi_terima_tgl_p.setSpacing(20);	    	    
//	    
	    
	    DateField tgl_pengambilan = new DateField();
	    tgl_pengambilan.setPropertyEditor(new DateTimePropertyEditor("dd/MM/yyyy"));
	    tgl_pengambilan.setFieldLabel("TGL Ambil");
	    tgl_pengambilan.setEmptyText("Pengambilan");
	    tgl_pengambilan.setName("tgl_pengambilan");	    
	    tgl_pengambilan.setWidth(100);
	    
	    multi_terima_tgl_p.add(tgl_pengambilan);
	    	    
	    fieldSet3.add(multi_terima_tgl_p, formData);
	    
	    panel.add(fieldSet3);  	     

	    FieldSet fieldSet2 = new FieldSet();  
	    fieldSet2.setHeading("Kualitas & Kuantitas Pengiriman");  
	    fieldSet2.setCollapsible(false);

	    FormLayout layout3 = new FormLayout();  
	    layout3.setLabelWidth(80);  
	    fieldSet2.setLayout(layout3);  

	    MultiField multi_kirim = new MultiField();
	    multi_kirim.setFieldLabel("Ash");
	    multi_kirim.setSpacing(20);
	    
	    ash_kirim = new TextField<String>();
	    ash_kirim.setName("ash_kirim");  
	    ash_kirim.setReadOnly(true);
	    ash_kirim.setWidth(90);
	    multi_kirim.add(ash_kirim);   	    
	    
	    LabelField lcv = new LabelField("CV:");
	    lcv.setWidth(20);
	    multi_kirim.add(lcv);
	    
	    cv_kirim = new TextField<String>();	    
	    cv_kirim.setName("cv_kirim");  
	    cv_kirim.setWidth(90);
	    cv_kirim.setReadOnly(true);
//	    cv_kirim.setFieldLabel("CV");    
//	    fieldSet2.add(cv_kirim, formData);

	    multi_kirim.add(cv_kirim);
	    
	    fieldSet2.add(multi_kirim, formData);
	    
	    MultiField multi_kirim_tm_ts = new MultiField();
	    multi_kirim_tm_ts.setFieldLabel("TM");
	    multi_kirim_tm_ts.setSpacing(20);
	    
	    tm_kirim = new TextField<String>();
//	    DateField berangkat = new DateField();
	    tm_kirim.setName("tm_kirim");  
	    tm_kirim.setFieldLabel("TM");    
	    tm_kirim.setWidth(90);
	    tm_kirim.setReadOnly(true);
//	    fieldSet2.add(tm_kirim, formData);	
	    
	    multi_kirim_tm_ts.add(tm_kirim);
	    
	    LabelField lts = new LabelField("TS:");
	    lts.setWidth(20);
	    multi_kirim_tm_ts.add(lts);
	    
	    
	    ts_kirim = new TextField<String>();
//	    DateField tiba = new DateField();
	    ts_kirim.setName("ts_kirim");  
	    ts_kirim.setWidth(90);
	    ts_kirim.setReadOnly(true);
//	    ts_kirim.setFieldLabel("TS");    
//	    fieldSet2.add(ts_kirim, formData);
	    
	    multi_kirim_tm_ts.add(ts_kirim);
	    
	    fieldSet2.add(multi_kirim_tm_ts, formData);
	    
	    MultiField multi_kirim_hgi_kr = new MultiField();
	    multi_kirim_hgi_kr.setFieldLabel("HGI");
	    multi_kirim_hgi_kr.setSpacing(20);
	  	    
	    
	    hgi_kirim = new TextField<String>();
//	    DateField tiba = new DateField();
	    hgi_kirim.setName("hgi_kirim");  
	    hgi_kirim.setWidth(90);
	    hgi_kirim.setReadOnly(true);
	    hgi_kirim.setFieldLabel("HGI");    
//	    fieldSet2.add(hgi_kirim, formData);	    
	    	    	   
	    multi_kirim_hgi_kr.add(hgi_kirim);
	    
	    LabelField ltsf = new LabelField("Vol:");
	    ltsf.setWidth(20);
	    
	    multi_kirim_hgi_kr.add(ltsf);
	    
	    vol_kirim = new TextField<String>();
	    vol_kirim.setName("vol_kirim");  
	    vol_kirim.setFieldLabel("Volume");
	    vol_kirim.setReadOnly(true);
	    vol_kirim.setWidth(90);
	    
	    multi_kirim_hgi_kr.add(vol_kirim);
	    
	    fieldSet2.add(multi_kirim_hgi_kr, formData);
	    
	    TextField<String> nama_surveyor = new TextField<String>();
	    nama_surveyor.setName("nama_surveyor");  
	    nama_surveyor.setFieldLabel("Surveyor");	    
	    nama_surveyor.setReadOnly(true);
	    fieldSet2.add(nama_surveyor, formData);	
	    	    
	    final TextField<String> id_transportir = new TextField<String>();  
	    id_transportir.setName("id_transportir");
	    id_transportir.setVisible(false);
	    id_transportir.setFieldLabel("id_transportir");    
	    fieldSet.add(id_transportir, formData);

	    final TextField<String> no_pengajuan = new TextField<String>();  
	    no_pengajuan.setName("no_pengajuan");
	    no_pengajuan.setVisible(false);
	    no_pengajuan.setFieldLabel("no_pengajuan");    
	    fieldSet.add(no_pengajuan, formData);
	    
	    final TextField<String> id_pemasok = new TextField<String>();  
	    id_pemasok.setName("id_pemasok");
	    id_pemasok.setVisible(false);
	    id_pemasok.setFieldLabel("id_pemasok");    
	    fieldSet.add(id_pemasok, formData);
	    
	    final TextField<String> id_pengiriman = new TextField<String>();  
	    id_pengiriman.setName("id_pengiriman");
	    id_pengiriman.setVisible(false);
	    id_pengiriman.setFieldLabel("id_pengiriman");    
	    fieldSet.add(id_pengiriman, formData);
	    
	    panel.add(fieldSet2);

	    ContentPanel p = new ContentPanel();
	    p.setHeaderVisible(false);	    
	    p.setButtonAlign(HorizontalAlignment.RIGHT);  
	    p.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {  
	      @Override  
	      public void componentSelected(ButtonEvent ce) {  
//	        grid.getStore().rejectChanges();  
	      }  
	    }));  
	    bSubmit = new Button("Submit"); 
	    
	    p.addButton(bSubmit);
	    
	    bSubmit.addSelectionListener( new SelectionListener<ButtonEvent>() {  
	      @Override  
	      public void componentSelected(ButtonEvent ce) {  
//	        grid.getStore().commitChanges();  
	    	  MessageBox.confirm("Info", "Apakah Anda Yakin Ingin Menyimpan Data?",new Listener<MessageBoxEvent>() {

					@Override
					public void handleEvent(MessageBoxEvent be) {
						// TODO Auto-generated method stub
						Button btn = be.getButtonClicked();
						if (btn.getText().equals("Yes")){
 
	    	  
					    	  Map mapParam = new FastMap();
					    	   Date tlgskrg = new Date();
					    	   
					    	   DateTimeFormat dtFormat = DateTimeFormat.getFormat("dd/MM/yyyy");	    	   
					    	   
					           
					            mapParam.put("tanggal", dtFormat.format(tlgskrg));
					            mapParam.put("id_surveyor", cboSurveyor.getValue().get("id_surveyor").toString());
					            mapParam.put("no_pengiriman", no_pengiriman.getValue());
					            mapParam.put("id_pengiriman", id_pengiriman.getValue());
					            mapParam.put("id_pemasok", id_pemasok.getValue());
					            mapParam.put("id_transportir", id_transportir.getValue());
					    		mapParam.put("no_pengajuan", no_pengajuan.getValue());
					    		mapParam.put("no_bongkar", no_bongkar.getValue());	    		
					    		mapParam.put("ash", ash_terima.getValue());
					    		mapParam.put("ts", ts_terima.getValue());
					    		mapParam.put("tm", tm_terima.getValue());
					    		mapParam.put("cv", cv_terima.getValue());
					    		mapParam.put("hgi", hgi_terima.getValue());
					    		mapParam.put("vol_terima", vol_terima.getValue());
					    		mapParam.put("jumlah_sampling",0);
					    		mapParam.put("volume",0);
					    		mapParam.put("status", "TERIMA");
					    		mapParam.put("no_sampling",0);
					    		mapParam.put("tgl_pengambilan","");
					    	    mapParam.put("id_pltu", Registry.get("idPltu").toString());
					    		mapParam.put("user", Registry.get("whoAmI").toString());
					    		mapParam.put("app_access", "WEB");
					    		mapParam.put("crud", "CREATE");
				//
					    		
					    		Set set = mapParam.entrySet(); 
					    		Iterator i = set.iterator(); 
					    		// Display elements 
					    		while(i.hasNext()) { 
					    		Map.Entry me = (Map.Entry)i.next(); 
						    		GWT.log(me.getKey() + ": " + me.getValue()); 
					    		} 
					    		
				//	    		MessageBox.alert("Informasi", "In progress", null);
				
					    		serviceSampling.insertPengirimanBB("SAMPLING", mapParam,new AsyncCallback<List<Map>>() {
					    			public void onFailure(Throwable caught) {
					    				GWT.log(caught.getMessage(), null);
					    			}
				
					    			public void onSuccess(List<Map> result) {	    				
					    				Info.display("debug ","notification code " + result );	    					    				
					    				aktivitasDermaga("sampling","BONGKAR","", "");
					    				MessageBox.alert("Informasi", " " + result, null);
					    			}
					    		});
					    }	
					}
				});
	      }  
	    });  

	    panel.add(p);
	    
	    return panel;  
	  }  
	  private Grid createGridSandar() {  
		  
		    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  

		    ColumnConfig column = new ColumnConfig();	    	     
		    
		    column = new ColumnConfig();  
		    column.setId("pemasok");  
		    column.setHeader("Pemasok");  
		    column.setWidth(150);  
		    configs.add(column); 

		    
		    column = new ColumnConfig();  
		    column.setId("nama_transport");  
		    column.setHeader("Nama kapal");    
		    column.setWidth(150);    
		    configs.add(column);  

		    column = new ColumnConfig();  
		    column.setId("no_pengiriman");  
		    column.setHeader("No Pengiriman");  
		    column.setWidth(100);  
		    configs.add(column);  	
		    
		    column = new ColumnConfig();  
		    column.setId("kode_jetty");  
		    column.setHeader("Jetty");  
		    column.setWidth(100);  
		    configs.add(column);  	  
		    
		    column = new ColumnConfig();  
		    column.setId("time_merapat");  
		    column.setHeader("Mulai Sandar");  
		    column.setDateTimeFormat(DateTimeFormat.getFormat("dd/MM/yyyy hh.mm"));
		    column.setWidth(150);  
		    configs.add(column);  
		    ColumnModel cm = new ColumnModel(configs);  
	  
	    gridKplSandar = new Grid(storeKplSandar, cm);  
	    gridKplSandar.getView().setEmptyText("Data Empty");
	    gridKplSandar.setLoadMask(true);  
	    gridKplSandar.mask("load Data ...","x-mask-loading");
	    gridKplSandar.setBorders(false);  
//	    grid.setAutoExpandColumn("pemasok");  
	    gridKplSandar.setBorders(true);  
	    gridKplSandar.addListener(Events.CellClick, new Listener<BaseEvent>() {            
        public void handleEvent(BaseEvent ge) {
        	try{

//        		String tgl_td = gridKplSandar.getSelectionModel().getSelectedItem().get("tgl_td");
//        		String norakor = gridKplAntri.getSelectionModel().getSelectedItem().get("kode_jetty").toString();
//            	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy"); 
//            	Date tgl = dateFormat.parse(test);
        		String mulai_sandar = gridKplSandar.getSelectionModel().getSelectedItem().get("time_merapat");
        		time_sandarT.setRawValue("00.00");
        		time_sandarD.setRawValue(mulai_sandar);
            	ash_kirim.setValue(gridKplSandar.getSelectionModel().getSelectedItem().get("ash").toString());
            	cv_kirim.setValue(gridKplSandar.getSelectionModel().getSelectedItem().get("cv").toString());
            	ts_kirim.setValue(gridKplSandar.getSelectionModel().getSelectedItem().get("ts").toString());
            	tm_kirim.setValue(gridKplSandar.getSelectionModel().getSelectedItem().get("tm").toString());

            	
        	}catch (Exception e) {
					// TODO: handle exception
        		e.getMessage();
				}

         	
        }
		});

	    return gridKplSandar;  
	  }   

	  private void aktivitasDermaga(final String module, final String codectrl , String put1,String param1){
		  
		  Map mapParam = new FastMap();	
		  mapParam.put("id_pltu", Registry.get("idPltu").toString());
		  if (module.equals("sampling")){
			  service.getListDermagaBy(codectrl, mapParam,new AsyncCallback<List<Map>>() {
		  			public void onFailure(Throwable caught) {
		  				GWT.log(caught.getMessage(), null);
		  			}
		  			public void onSuccess(List<Map> result) {
		  						  				
		  			     if (codectrl.equals("SANDAR")){
		  			    	storeKplSandar.removeAll();
		  			    	storeKplSandar.add(ClientModule.setListBaseModelFromListMap(result));
		  			    	gridKplSandar.unmask();
		  			     }else if(codectrl.equals("BANDINGSAMPLING")){
			  			    	storeKplBongkar.removeAll();
			  			    	storeKplBongkar.add(ClientModule.setListBaseModelFromListMap(result));
			  			    	gridKplBongkar.unmask();
		  			    	 
		  			     }
		  				
		  			}
		  		});
		  }else if (module.equals("master")){

			  mapParam.put("id_pltu", Registry.get("idPltu").toString());
				  service.getMaster(codectrl, mapParam,new AsyncCallback<List<Map>>() {
			  			public void onFailure(Throwable caught) {
			  				GWT.log(caught.getMessage(), null);
			  			}
			  			public void onSuccess(List<Map> result) {			  
					    	storeSurveyor.removeAll();
					    	storeSurveyor.add(ClientModule.setListBaseModelFromListMap(result));
					    	
			  			}
			  		});

			}
		   
	  }

}
